/* Andreas Baum
 * IMClientApp.java
 * Handles the connection of an IM client to the IM server
 * CS 78 - Networks - Programming Assignment 1
 */


package jbpServerTester;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import jbpClientTester.DataThread;




public class JBPServerTester {

	public static int SERVER_PORT = 4444;
	public static int ITUNES_PORT = 3689;
	public static ServerSocket extSocket;

	public JBPServerTester() {
	}

	public static void main(String args[]) throws IOException {

		DataThread sExtThread;
		System.out.println("\t*** Welcome to the Simple Bonjour Proxy! ***");		

		Socket iTunesSocket = new Socket("localhost", ITUNES_PORT);
		DataThread iTunesDataThread = new DataThread(iTunesSocket, "iTunesDataThread");

		System.out.println("Connected to iTunes.");

		// Bind to port:
		try {
			extSocket = new ServerSocket(SERVER_PORT);
		} catch (IOException e) {
			System.out.println("ERROR: Could not listen on port: " + SERVER_PORT);
			System.exit(-1);
		}
		// Output information:
		System.out.println("Listening on port " + SERVER_PORT + ".");


		// listen for a new connection and
		// create a client thread to handle the client:
		sExtThread = new DataThread(extSocket.accept(), "extThread");
		System.out.println("Received connection from " 
				+ extSocket.getInetAddress().getHostName() +".");

		sExtThread.setOtherThread(iTunesDataThread);
		iTunesDataThread.setOtherThread(sExtThread);
		
		System.out.println("Server-side pipeline established.");
//		-------------------------------------------------------------------------



	}

}